package com.ruoyi.user.controller;

import com.ruoyi.common.core.cg.dto.AddCommunityDto;
import com.ruoyi.common.core.cg.dto.CommunityDto;
import com.ruoyi.common.core.cg.pojo.Community;
import com.ruoyi.common.core.cg.pojo.Location;
import com.ruoyi.common.core.cg.result.Result;
import com.ruoyi.user.service.CommunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("community")
public class CommunityController {
    @Autowired
    private CommunityService service;
    @RequestMapping("findByUserId")
    public Result findById(Integer id){
        try {
            Community community = service.findByUserId(id);
            return new Result(true,"查询成功",community);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"查询失败");
        }
    }
    @RequestMapping("batchAddCommunity")
    public Result batchAddCommunity(@RequestBody CommunityDto dto){
        try {
            service.batchAddCommunity(dto);
            return new Result(true,"查询成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"查询失败");
        }
    }

    /**
     * 查询拼团点信息
     * @param dto
     * @return
     */
    @RequestMapping("findCommunityInfo")
    public Result findCommunityInfo(@RequestBody CommunityDto dto){
        try {
            return service.findCommunityInfo(dto);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"查询失败");
        }
    }

    /**
     * 切换用户拼团点
     * @param dto
     * @return
     */
    @RequestMapping("changeUserCommunity")
    public Result changeUserCommunity(@RequestBody AddCommunityDto dto){
        try {
            service.changeUserCommunity(dto);
            return new Result(true,"切换拼团点成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"切换拼团点失败");
        }
    }
}
